package com.css.fxfzysx.modules.cztDataMange.controller;

import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.modules.cztDataMange.service.BasicLibraryService;
import com.css.fxfzysx.modules.vabStructure.param.CustomVulnerabilityParam;
import com.css.fxfzysx.modules.vabStructure.param.MatchingParam;
import com.css.fxfzysx.modules.vabStructure.param.PageParam;
import com.css.fxfzysx.modules.vabStructure.vo.GenerateVulnerabilityMatrixVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * 基础库管理
 */
@RestController
@RequestMapping("basicLibrary")
@Slf4j
public class BasicLibraryController {

    @Autowired
    private BasicLibraryService basicLibraryService;

    /**
     * 基础库分页查询
     */
    @GetMapping("queryBasicLibrary")
    public RestResponse queryBasicLibrary(CustomVulnerabilityParam param, HttpServletRequest request){
        return basicLibraryService.queryBasicLibrary(param,request);
    }

    /**
     * 基础库分页查询 风险区划调用
     */
    @GetMapping("page")
    public RestResponse page(PageParam param){
        try {
            return RestResponse.succeed(basicLibraryService.page(param));
        } catch (Exception e) {
            log.error("get page error:{}",e.getMessage(),e);
            return RestResponse.fail("失败!");
        }
    }

    /**
     * 移出基础库
     */
    @GetMapping("removeBasicLibrary")
    public RestResponse removeBasicLibrary(String dataType,String id,String province){
        return basicLibraryService.removeBasicLibrary(dataType,id,province);
    }

    /**
     * 生成矩阵
     */
    @GetMapping("getMatrix")
    public RestResponse getMatrix(String dataType,String id,String province){
        return basicLibraryService.getMatrix(dataType,id,province);
    }

    /**
     * 生成矩阵(风险区划系统)
     */
    @GetMapping("getByIdAndType")
    public RestResponse getByIdAndType(String dataType,String pId,String province){
        try {
            List<GenerateVulnerabilityMatrixVo> list =  basicLibraryService.getByIdAndType(dataType,pId,province);
            return RestResponse.succeed(list);
        } catch (Exception e) {
            return RestResponse.fail("失败!");
        }
    }

    /**
     * 导出矩阵
     */
    @GetMapping("exportMatrix")
    public void exportMatrix(HttpServletResponse response,String dataType, String id,String province){
        basicLibraryService.exportMatrix(response,dataType,id,province);
    }

    @PostMapping("getByRegion")
    public RestResponse getByRegion(@RequestBody MatchingParam param){
        try {
            return RestResponse.succeed(basicLibraryService.getByRegion(param));
        } catch (Exception e) {
            log.error(" getByRegion error:{}",e.getMessage(),e);
            return RestResponse.fail("失败!");
        }
    }
}
